package cn.tedu.csmall.cart.webapi.kafka;

import cn.tedu.csmall.commons.pojo.cart.entity.Cart;
import com.google.gson.Gson;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class Consumer {


    @KafkaListener(topics = Producer.TOPIC_KEY)
    public void received(ConsumerRecord<String, String> record){
        String json = record.value();
        Gson gson = new Gson();
        Cart cart = gson.fromJson(json, Cart.class);
        System.out.println("cart = " + cart);
    }
}
